﻿using System;
using System.Web;
using System.Web.Routing;

using Flagwind.Plugins.Builders;

namespace Flagwind.Web.Plugins.Builders
{
	public class RouteIgnoreBuilder : RouteBuilder
	{
		public override object Build(BuilderContext context)
		{
			return new IgnoreRouteInternal(context.Builtin.Properties.GetRawValue("url"))
			{
				Constraints = this.ResolveValues(context.Builtin.Properties.GetValue<string>("constraints"), context.Builtin)
			};
		}

		private sealed class IgnoreRouteInternal : Route
		{
			public IgnoreRouteInternal(string url) : base(url, new StopRoutingHandler())
			{
			}

			public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary routeValues)
			{
				return null;
			}
		}
	}
}
